#!/usr/bin/env bash

WM=marco
BACKEND="glx"
VSYNC="opengl-swc"

if [ ! -x $(which ${WM}) ] && [ ! -x $(which compton) ]; then
    echo "ERROR! Can't find required components for ${WM} and compton."
    exit 1
fi

COMPTON_PIDS=$(pidof compton)
if [ $? -eq 0 ]; then
    echo "Killing compton"
    for PID in ${COMPTON_PIDS}; do
        kill -9 ${PID}
    done
fi

# Replace window manager and force compositing off.
${WM} --no-composite --replace &
sleep 0.3

# Allow users to override the defaults by creating their own config
# for this wrapper.
if [ -f ${HOME}/.config/${WM}-compton.conf ]; then
    compton \
        --config ${HOME}/.config/${WM}-compton.conf &
else
    compton \
        --config /dev/null \
        --backend ${BACKEND} \
        --vsync ${VSYNC} \
        --detect-rounded-corners \
        --detect-client-leader \
        --detect-transient \
        --detect-client-opacity \
        --paint-on-overlay \
        --glx-no-stencil \
        --glx-swap-method undefined \
        --unredir-if-possible \
        --unredir-if-possible-exclude "class_g = 'Mate-screensaver'" \
        --inactive-opacity-override \
        --mark-wmwin-focused \
        --mark-ovredir-focused \
        --use-ewmh-active-win \
        -r 10 -o 0.225 -l -12 -t -12 \
        -c -C -G \
        --fading \
        --fade-delta=4 \
        --fade-in-step=0.03 \
        --fade-out-step=0.03 \
        --shadow-exclude "! name~=''" \
        --shadow-exclude "name = 'Notification'" \
        --shadow-exclude "name = 'Plank'" \
        --shadow-exclude "name = 'Docky'" \
        --shadow-exclude "name = 'Kupfer'" \
        --shadow-exclude "name *= 'compton'" \
        --shadow-exclude "class_g = 'albert'" \
        --shadow-exclude "class_g = 'Conky'" \
        --shadow-exclude "class_g = 'Kupfer'" \
        --shadow-exclude "class_g = 'Synapse'" \
        --shadow-exclude "class_g ?= 'Notify-osd'" \
        --shadow-exclude "class_g ?= 'Cairo-dock'" \
        --shadow-exclude "class_g = 'Cairo-clock'" \
        --shadow-exclude "_GTK_FRAME_EXTENTS@:c" &
fi
